package cn.bincker.mycaptcha.basic.properties;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.File;
import java.time.Duration;

@Getter
@Setter
@NoArgsConstructor
public class CacheConfigProperties {
    /**
     * 是否启用缓存
     */
    private Boolean enabled = true;

    /**
     * 缓存目录
     */
    private File cachePath = new File(".captcha-cache");

    /**
     * 验证码缓存目录名称
     */
    private String captchaPathName = "captcha";

    /**
     * 答案缓存目录名称
     */
    private String answerPathName = "answer";

    /**
     * 最大缓存数量
     */
    private Integer maxCacheItems = 10000;

    /**
     * 存活时间
     */
    private Long survivalTime = Duration.ofDays(7).toMillis();

    public File getCaptchaPath(){
        return new File(cachePath, captchaPathName);
    }

    public File getAnswerPath(){
        return new File(cachePath, answerPathName);
    }

    public CacheConfigProperties(File cachePath) {
        this.cachePath = cachePath;
    }
}
